package com.shunda.ysdgj.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
    // 插入时进行的操作，@TableField(fill = FieldFill.INSERT)
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "created", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "updated", LocalDateTime::now, LocalDateTime.class);
    }

    // 更新时进行的操作，@TableField(fill = FieldFill.UPDATE)
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updated", LocalDateTime::now, LocalDateTime.class);
    }
}
